package com.muyu.danmo.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.danmo.domain.DanmoCommunity;
import com.muyu.danmo.domain.DanmoInformationMap;
import com.muyu.danmo.service.IDanmoInformationMapService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 个人信息相关星图Controller
 *
 * @author kunzong
 * @date 2024-11-30
 */
@RestController
@RequestMapping("/DanmoInformationMap")
public class DanmoInformationMapController extends BaseController {
    @Autowired
    private IDanmoInformationMapService danmoInformationMapService;

    /**
     * 查询个人信息相关星图列表
     */
//    @RequiresPermissions("system:DanmoInformationMap:list")
    @GetMapping("/list")
    public Result list(DanmoInformationMap danmoInformationMap) {
        startPage();
        List<DanmoInformationMap> list = danmoInformationMapService.selectDanmoInformationMapList(danmoInformationMap);
        return getDataTable(list);
    }

    /**
     * 导出个人信息相关星图列表
     */
//    @RequiresPermissions("system:DanmoInformationMap:export")
    @Log(title = "个人信息相关星图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoInformationMap danmoInformationMap) {
        List<DanmoInformationMap> list = danmoInformationMapService.selectDanmoInformationMapList(danmoInformationMap);
        ExcelUtil<DanmoInformationMap> util = new ExcelUtil<DanmoInformationMap>(DanmoInformationMap.class);
        util.exportExcel(response, list, "个人信息相关星图数据");
    }

    /**
     * 获取个人信息相关星图详细信息
     */
//    @RequiresPermissions("system:DanmoInformationMap:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id) {
        return success(danmoInformationMapService.selectDanmoInformationMapById(id));
    }

    /**
     * 新增个人信息相关星图
     */
//    @RequiresPermissions("system:DanmoInformationMap:add")
    @Log(title = "个人信息相关星图", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody DanmoInformationMap danmoInformationMap) {
        return Result.success(danmoInformationMapService.insertDanmoInformationMap(danmoInformationMap));
    }

    /**
     * 修改个人信息相关星图
     */
//    @RequiresPermissions("system:DanmoInformationMap:edit")
    @Log(title = "个人信息相关星图", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoInformationMap danmoInformationMap) {
        return toAjax(danmoInformationMapService.updateDanmoInformationMap(danmoInformationMap));
    }

    /**
     * 删除个人信息相关星图
     */
//    @RequiresPermissions("system:DanmoInformationMap:remove")
    @Log(title = "个人信息相关星图", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids) {
        return toAjax(danmoInformationMapService.deleteDanmoInformationMapByIds(ids));
    }

    /**
     * 获取个人信息相关星图详细信息
     */
//    @RequiresPermissions("system:DanmoInformationMap:query")
    @GetMapping(value = "information/{informationId}")
    public Result informationId(@PathVariable("informationId") Long informationId) {
        DanmoInformationMap danmoInformationMap = new DanmoInformationMap();
        PageHelper.startPage(danmoInformationMap.getPageNum(), danmoInformationMap.getPageSize());
        List<DanmoInformationMap> list = danmoInformationMapService.selectDanmoInformationMapByInformationId(informationId);
        if (list.size() == 0) {
            return Result.success(list, "暂无信息");
        }
        PageInfo<DanmoInformationMap> danmoCommunityPageInfo = new PageInfo<>(list);
        return Result.success(danmoCommunityPageInfo);
    }
}
